package com.heima.web.controller;

import com.heima.mapper.UserPlusMapper;
import com.heima.pojo.User;
import com.heima.pojo.utils.Result;
import com.heima.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * @ClassName UserController
 * @Author Administrator
 * @create 2022/11/10 20:28
 */
@RestController
@RequestMapping("/v1/user")
public class UserController {

    @Autowired
    UserService userService;

    @Autowired
    UserPlusMapper userPlusMapper;

    @GetMapping("/findByClassId")
    public Result findUserByClassId(HttpServletRequest request){
        HttpSession session = request.getSession();
        Integer classId = (Integer) session.getAttribute("classId");
        return userService.findByClassId(classId);
    }

    @PostMapping("/addIntegral")
    public Result addIntegral(@RequestBody User user){
        return userService.addIntegral(user.getId(),user.getIntegral());
    }

    @GetMapping("/resetGScoreByGroupId/{classId}")
    public Result resetGScoreByGroupId(@PathVariable Integer classId){
        return userService.resetGScoreByGroupId(classId);
    }
}
